import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/sales/api/v1';

const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询整车年度销售目标'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询整车年度销售目标详情'
});
const exportDesc = formatMessage({
    id: 'api.message.queryExport',
    defaultMessage: '导出'
});
const exportDetailDesc = formatMessage({
    id: 'api.message.exportDetailDesc',
    defaultMessage: '导出明细'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/vehicleStock/init`, null, dto.InitDataStruct)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getListDesc));
// 查询列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleStocks/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/vehicleStocks/details?${queryString}`, null, null)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
};
//导出
export const queryExport = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/vehicleStocks/forCurrentUser/export?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
//导出明细
export const queryExportDetail = queryCondition => {
    const queryString = stringify(queryCondition);
    return request(`${baseUrl}/vehicleStocks/forCurrentUser/exportDetails?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDetailDesc))
        .then(res => res.data);
};
//导入整整车总代车辆模板
export const importDealerTemp = () => request(`${baseUrl}/vehicleStocks/forDealer/importTemp`)
    .then(handleFetchResultNotification(REQUEST_TYPE.query, null)).then(res => res.data);
